const { Add, Update, QueryOne } = require('../db/dbhelper');
var { init, format } = require('../models/people');

//保存
const personlabelSave = async function (doc) {
  try {
    if (!doc.pcode) {
      return {
        code: 1,
        msg: 'pcode参数不能为空'
      }
    }
    let pl = await QueryOne('hzz_personlabels', { pcode: doc.pcode }, null);
    if (pl) {
      await Update('hzz_personlabels', format(doc));
    } else {
      await Add('hzz_personlabels', init(doc));
    }
    return {
      code: 0,
      msg: '保存我的标签成功'
    }
  } catch (error) {
    return {
      code: 1,
      msg: error ? error.message : '保存我的标签异常'
    }
  }
}

//查询详情
const personlabelQueryOne = function (pcode) {
  return QueryOne('hzz_personlabels', { pcode: pcode }, null);
}

module.exports = {
  personlabelSave,
  personlabelQueryOne
}